//
//  MineViewController.m
//  MonitoringNetwork
//
//  Created by admin on 2017/11/23.
//  Copyright © 2017年 Shenzhen Xinwo Transport. All rights reserved.
//

#import "MineViewController.h"
#import "AboutViewController.h"
#import "ModifyPassWordViewController.h"
#import "UILabel+BasicAttributes.h"
#import "UIImage+Rotate.h"
#import "LoginViewController.h"
#import "BaseNavigationViewController.h"

@interface MineViewController ()
@property (nonatomic,strong)UIView *baseView;
@end

@implementation MineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNavigationTitleWithTitle:@"个人中心"];
    [self loadUI];
    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipemethod:)];
    swipe.direction = UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:swipe];
}
- (void)swipemethod:(UISwipeGestureRecognizer *)swipe
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}


- (void)loadUI
{
    //设置导航栏返回按钮
    [self setLeftBarButtonItemWithNormalImageName:@"backNormal" andSelectImageName:@"backSel"];
    UIView *viewOne = [UIView new];
    [self.view addSubview:viewOne];
    [viewOne mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.view);
        make.top.mas_equalTo(self.view.mas_top).offset(NavationBarHeight);
        make.height.mas_equalTo(40);
    }];
    UIView *lineOne = [UIView new];
    lineOne.backgroundColor = [UIColor colorWithRed:0.88f green:0.88f blue:0.88f alpha:1.00f];
    [viewOne addSubview:lineOne];
    [lineOne mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(viewOne);
        make.height.mas_equalTo(.8f);
    }];
    
    UIView *viewTwo = [UIView new];
    [self.view addSubview:viewTwo];
    [viewTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.view);
        make.top.mas_equalTo(viewOne.mas_bottom);
        make.height.mas_equalTo(40);
    }];
    UIView *lineTwo = [UIView new];
    lineTwo.backgroundColor = [UIColor colorWithRed:0.88f green:0.88f blue:0.88f alpha:1.00f];
    [viewTwo addSubview:lineTwo];
    [lineTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(viewTwo);
        make.height.mas_equalTo(.8f);
    }];
    
//    UIView *viewThree = [UIView new];
//    [self.view addSubview:viewThree];
//    [viewThree mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.right.mas_equalTo(self.view);
//        make.top.mas_equalTo(viewTwo.mas_bottom);
//        make.height.mas_equalTo(kHeightOfPt(151));
//    }];
//    UIView *lineThree = [UIView new];
//    lineThree.backgroundColor = [UIColor colorWithRed:0.88f green:0.88f blue:0.88f alpha:1.00f];
//    [viewThree addSubview:lineThree];
//    [lineThree mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.right.bottom.mas_equalTo(viewThree);
//        make.height.mas_equalTo(kHeightOfPt(1));
//    }];
    
    UIView *viewFour = [UIView new];
    [self.view addSubview:viewFour];
    [viewFour mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.view);
        make.top.mas_equalTo(viewTwo.mas_bottom);
        make.height.mas_equalTo(40);
    }];
    UIView *lineFour = [UIView new];
    lineFour.backgroundColor = [UIColor colorWithRed:0.88f green:0.88f blue:0.88f alpha:1.00f];
    [viewFour addSubview:lineFour];
    [lineFour mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(viewFour);
        make.height.mas_equalTo(.8f);
    }];
    
    UILabel *titleNameLabel = [UILabel LabelWithFont:BigFontSize andColor:[UIColor colorWithRed:0.20f green:0.20f blue:0.20f alpha:1.00f] andTextAlignment:left];
    titleNameLabel.text = @"用户名";
    [viewOne addSubview:titleNameLabel];
    [titleNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(viewOne.mas_left).offset(kWidthOfPt(60));
        make.centerY.mas_equalTo(viewOne);
    }];
    
    UILabel *nameLabel = [UILabel LabelWithFont:BigFontSize andColor:[UIColor colorWithRed:0.20f green:0.20f blue:0.20f alpha:1.00f] andTextAlignment:left];
    nameLabel.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserName"];
    [viewOne addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(viewOne.mas_left).offset(kWidthOfPt(60)+kScreenWidth*0.25);
        make.centerY.mas_equalTo(viewOne);
    }];
    
    UILabel *titlePassWordLabel = [UILabel LabelWithFont:BigFontSize andColor:[UIColor colorWithRed:0.20f green:0.20f blue:0.20f alpha:1.00f] andTextAlignment:left];
    titlePassWordLabel.text = @"修改密码";
    [viewTwo addSubview:titlePassWordLabel];
    [titlePassWordLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(viewTwo.mas_left).offset(kWidthOfPt(60));
        make.centerY.mas_equalTo(viewTwo);
    }];
    

    
    UIImageView *imageView = [UIImageView new];
    imageView.image = [[UIImage imageNamed:@"backSel"] rotate:UIImageOrientationDown];
    [viewTwo addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(viewTwo);
        make.right.mas_equalTo(viewTwo.mas_right).offset(kWidthOfPt(-60));
        make.height.mas_equalTo(kHeightOfPt(60));
        make.width.mas_equalTo(imageView.mas_height);
    }];
//
//    UILabel *titleAboutLabel = [UILabel LabelWithFont:BigFontSize andColor:[UIColor colorWithRed:0.20f green:0.20f blue:0.20f alpha:1.00f] andTextAlignment:left];
//    titleAboutLabel.text = @"关于我们";
//    [viewThree addSubview:titleAboutLabel];
//    [titleAboutLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(viewThree.mas_left).offset(kWidthOfPt(60));
//        make.centerY.mas_equalTo(viewThree);
//    }];
//
//    UIImageView *aboutImageView = [UIImageView new];
//    aboutImageView.image = [[UIImage imageNamed:@"backSel"] rotate:UIImageOrientationDown];
//    [viewThree addSubview:aboutImageView];
//    [aboutImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.mas_equalTo(viewThree);
//        make.right.mas_equalTo(viewThree.mas_right).offset(kWidthOfPt(-60));
//        make.height.mas_equalTo(kHeightOfPt(60));
//        make.width.mas_equalTo(aboutImageView.mas_height);
//    }];
    
    UILabel *titleVersionLabel = [UILabel LabelWithFont:BigFontSize andColor:[UIColor colorWithRed:0.20f green:0.20f blue:0.20f alpha:1.00f] andTextAlignment:left];
    titleVersionLabel.text = @"版本号";
    [viewFour addSubview:titleVersionLabel];
    [titleVersionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(viewFour.mas_left).offset(kWidthOfPt(60));
        make.centerY.mas_equalTo(viewFour);
    }];
    
    UILabel *versionLabel = [UILabel LabelWithFont:BigFontSize andColor:[UIColor colorWithRed:0.20f green:0.20f blue:0.20f alpha:1.00f] andTextAlignment:left];
    versionLabel.text = [NSString stringWithFormat:@"V %@ ",[[[NSBundle mainBundle]infoDictionary] objectForKey:@"CFBundleShortVersionString"]];
    [viewFour addSubview:versionLabel];
    [versionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(viewOne.mas_left).offset(kWidthOfPt(60)+kScreenWidth*0.25);
        make.centerY.mas_equalTo(viewFour);
    }];
    
    UIButton *modifyBtn = [UIButton new];
    [modifyBtn addTarget:self action:@selector(modifyBtnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    [viewTwo addSubview:modifyBtn];
    [modifyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(viewTwo);
    }];
    
//    UIButton *aboutBtn = [UIButton new];
//    [aboutBtn addTarget:self action:@selector(aboutBtnDidClick:) forControlEvents:UIControlEventTouchUpInside];
//    [viewThree addSubview:aboutBtn];
//    [aboutBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.right.top.bottom.mas_equalTo(viewThree);
//    }];
    
    

    UIButton *logOutBtn = [UIButton new];
    [logOutBtn setTitle:@"退出登录" forState:UIControlStateNormal];
    logOutBtn.layer.cornerRadius = 2.0f;
    logOutBtn.clipsToBounds = YES;
    logOutBtn.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:LagerFontSize];
    [logOutBtn setBackgroundImage:[UIImage imageNamed:@"roundBtn"] forState:UIControlStateNormal];
    [logOutBtn addTarget:self action:@selector(logOutBtnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:logOutBtn];
    [logOutBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.centerY.mas_equalTo(self.view.mas_top).offset(kScreenHeight*0.93);
        make.width.mas_equalTo(kScreenWidth*0.9);
        make.height.mas_equalTo(37);
    }];
    
}
- (void)logOutBtnDidClick:(UIButton *)sender
{
    LoginViewController *LoginVC = [LoginViewController new];
    BaseNavigationViewController *navc = [[BaseNavigationViewController alloc] initWithRootViewController:LoginVC];
    [[[UIApplication sharedApplication]delegate]window].rootViewController = navc;
    [[[[UIApplication sharedApplication]delegate]window] makeKeyAndVisible];
}
- (void)modifyBtnDidClick:(UIButton *)sender
{
    ModifyPassWordViewController *modifyVC = [ModifyPassWordViewController new];
    [self.navigationController pushViewController:modifyVC animated:YES];
}
- (void)aboutBtnDidClick:(UIButton *)sender
{
    AboutViewController *aboutVc = [AboutViewController new];
    [self.navigationController pushViewController:aboutVc animated:YES];
}
- (void)leftItemBtnClick:(UIButton *)sender
{
    [super leftItemBtnClick:sender];
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}



@end
